﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using DoAnTN.Buissiness;
using DoAnTN.Entity;
namespace DoAnTN.GUI
{
    public partial class UCSoDoPhong : UserControl
    {
        private int soTang = SoTangDAO.soTang();
        private int soPhong = 7;
        string[,] mang = PhongDAO.SoDoPhong();
        private int h = 0;
        private int soHang = ((PhongDAO.TongSoPhong() - 1 / 7)) + 1;

        public UCSoDoPhong()
        {
            InitializeComponent();
            Load();
        }

        public void Load() {
            Font font = new Font("Tahoma",12);
            TableLayoutPanel layout = new System.Windows.Forms.TableLayoutPanel();
            layout.ColumnCount = 7;
            layout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 130));
            layout.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 130));
            layout.Location = new System.Drawing.Point(110, 10);
            layout.Name = "tableLayoutPanel1";
            layout.RowCount = 15;
            layout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 70));
            layout.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 70));
            layout.Size = new System.Drawing.Size(130 * soPhong + 10, 75 * 15 + 10);
            layout.TabIndex = 2;
            this.Controls.Add(layout);

            for (int i = 0; i < soTang; i++)
            {
                Label label1 = new System.Windows.Forms.Label();
                label1.SuspendLayout();
                label1.AutoSize = true;
                label1.Font = new System.Drawing.Font("Tahoma", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                label1.Location = new System.Drawing.Point(15, (i + h)*70+32);
                label1.Name = (i + 1).ToString();
                label1.Size = new System.Drawing.Size(77, 24);
                label1.TabIndex = 0;
                label1.Text = "TẦNG " + (i + 1 ).ToString();
                this.Controls.Add(label1);
               // label1.DoubleClick += new EventHandler(label1)
                int k = 0;
                for (int j = 0; j < PhongDAO.soPhongCuaTang(i+1); j++)
                {
                    string tenPhong = mang[i + 1, j + 1];
                    Button btn = new System.Windows.Forms.Button();
                    btn.Name = tenPhong;
                    btn.Size = new System.Drawing.Size(125, 65);
                    btn.TabIndex = 1;
                    btn.Font = font;
                    btn.Text = tenPhong;
                    if (PhongDAO.MauSac(tenPhong) == Color.Black)
                    {
                        btn.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
                        btn.UseVisualStyleBackColor = true;
                        btn.Image = Image.FromFile("D:\\DoAnTN\\DoAnTN\\Icon\\22x22\\clear.png");
                    }
                   else if (PhongDAO.MauSac(tenPhong) == Color.Green)
                    {
                        btn.UseVisualStyleBackColor = true;
                    }
                    else
                    {
                        btn.BackColor = PhongDAO.MauSac(mang[i + 1, j + 1]);
                    }
                    if (j>6)
                    {
                        k = j / 7;
                        layout.Controls.Add(btn, j - 7, i + h + k);

                    }
                    else
                    {
                        layout.Controls.Add(btn, j, i + h);

                    }
                    this.toolTip1.SetToolTip(btn, "Phong" +tenPhong+" Loai" + LoaiPhongDAO.tenLoaiPhong(PhongDAO.maLoaiPhong(tenPhong)));
                }
                if (k > 0)
                {
                    h = h + k;
                }
            }

        }
    }
}
